package com.jishuo.nontax.web.bill;

import com.jishuo.base.annotation.UserAuthority;
import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.GridResult;
import com.jishuo.base.bean.Pagination;
import com.jishuo.base.bean.vo.UserVO;
import com.jishuo.base.config.AppConfig;
import com.jishuo.base.service.UserService;
import com.jishuo.nontax.bean.vo.PayFiscVO;
import com.jishuo.nontax.bfc.service.FiscService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @auther dinggaofei
 * @Date 2023/3/3 11:25
 */
@Slf4j
@Controller
@RequestMapping(value = "/bill/fisc", name = "国库单据")
@UserAuthority(menu={"bill/fisc/fisc","sys/basedata/basedata"})
public class FiscController {
    @Resource
    private FiscService fiscService;
    @Resource
    private UserService userService;

    private String prefix = "bill/";

    @RequestMapping(value = {"fisc"}, name = "化解国库首页")
    public String index() {
        return prefix + "fisc";
    }

    @ResponseBody
    @RequestMapping(value = "listFisc", name = "化解国库列表")
    public GridResult<PayFiscVO> listFisc(PayFiscVO payFiscVO, Pagination pagination) {
        return new GridResult<>(fiscService.listPayFisc(payFiscVO, pagination));
    }


    @ResponseBody
    @RequestMapping(value = "sendFisc", name = "发送国库单据")
    public BaseResult sendFisc(String billids , String userpwd, String usercode, HttpSession session){
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return  fiscService.sendFisc(billids);
    }

    @ResponseBody
    @RequestMapping(value = "cleanFisc",name = "冲销国库单据")
    public BaseResult cleanFisc(String billids,String userpwd,String usercode, HttpSession session){
        UserVO user = (UserVO) session.getAttribute(AppConfig.LOGIN_USER_SESSION_KEY);
        BaseResult ret = userService.chkAuthUser(usercode, userpwd, user);
        if (!ret.isSuccess()) return ret;
        return  fiscService.cleanFisc(billids,usercode);

    }

    @ResponseBody
    @RequestMapping(value = "fiscEXport",name = "化解国库导出")
    public void fiscExport(long bankid, String paybankdt, HttpServletResponse response){
          fiscService.fiscExport(bankid, paybankdt ,response);
    }

}
